<%
/**
 参数:
 - user: 用户对象 (必需)
 - size: 尺寸类名 (可选，默认 'w-12 h-12')
 - classes: 额外的CSS类 (可选)
 **/
%>
<%
const avatarSize = typeof size !== 'undefined' ? size : 'w-12 h-12';
const extraClasses = typeof classes !== 'undefined' ? classes : '';
const avatarUrl = user.avatar || null;
const avatarAlt = user.name || user.username || 'Avatar';
const initial = (user.name || user.username || 'U')[0].toUpperCase();
%>

<% if (avatarUrl) { %>
    <img src="<%= avatarUrl %>"
         alt="<%= avatarAlt %>"
         class="<%= avatarSize %> <%= extraClasses %> rounded-full object-cover"
         onerror="this.src='/images/default.svg'; this.onerror=null;"
         loading="lazy"/>
<% } else { %>
    <div class="<%= avatarSize %> <%= extraClasses %> rounded-full bg-blue-500 flex items-center justify-center text-white font-medium">
        <%= initial %>
    </div>
<% } %>